package itheima.moc.myreflect3;

import java.lang.reflect.Constructor;

public class ReflectDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException {
        //clazz.getConstructors() 返回所有     公共构造（public）方法对象的数组
        //clazz.getDeclaredConstructors() 返回所有     构造方法对象的数组
        //clazz.getConstructor()  返回    单个    公共构造方法对象
        //clazz.getDeclaredConstructor()  返回    单个构造方法
//        method1();            先用类获取对象名
//        method2();            再用对象名点方法获取各种无参与有参构造
//        methhod3();
        //clazz.getDeclaredConstructor()  返回    单个构造方法
        Class clazz = Class.forName("itheima.moc.myreflect3.Student");
        Constructor declaredConstructor = clazz.getDeclaredConstructor(String.class);
        System.out.println(declaredConstructor);
    }

    private static void methhod3() throws ClassNotFoundException, NoSuchMethodException {
        //clazz.getConstructor()  返回    单个    公共构造方法对象
        Class clazz = Class.forName("itheima.moc.myreflect3.Student");
        Constructor constructor = clazz.getConstructor();
        System.out.println(constructor);
        Constructor constructor1 = clazz.getConstructor(String.class,int.class);
        System.out.println(constructor1);
    }

    private static void method2() throws ClassNotFoundException {
        //clazz.getDeclaredConstructors() 返回所有     构造方法对象的数组
        Class clazz = Class.forName("itheima.moc.myreflect3.Student");
        Constructor[] declaredConstructors = clazz.getDeclaredConstructors();
        for (Constructor declaredConstructor : declaredConstructors) {
            System.out.println(declaredConstructor);
        }
    }

    private static void method1() throws ClassNotFoundException {
        //clazz.getConstructors() 返回所有     公共构造（public）方法对象的数组
        Class clazz = Class.forName("itheima.moc.myreflect3.Student");
        Constructor[] constructors = clazz.getConstructors();
        for (Constructor constructor : constructors) {
            System.out.println(constructor);
        }
    }
}
